<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String flag = request.getParameter("flag");
	String tablename = "";
	String id="";
	if(!"".equals(flag)&&null!=flag&&"0".equals(flag))
	{
		tablename = request.getParameter("tablename");
		id=request.getParameter("id");
		System.out.println(id);
	    String colname = request.getParameter("colname");
	    String disname = request.getParameter("disname");
	    String fileColname = request.getParameter("fileColname");
	    
	    String[] disnamearray = disname.split(",");
	    String disnameshow = "";
	    String disnameshow1 = "{'ID':'\"+row."+colname+"+\"'";
	   	   for(int i=0;i<disnamearray.length;i++){
	   			disnameshow += "{name:'"+disnamearray[i]+"',index:'"+disnamearray[i]+"', width:360},";
	   			disnameshow1 += ",'NAME':'\"+row."+disnamearray[i]+"+\"'";
	   		}
	   	  disnameshow1+="}";
	    request.setAttribute("tablename",tablename);
	    request.setAttribute("colname",colname);
	    request.setAttribute("disname",disname);
	    request.setAttribute("fileColname",fileColname);
	    if(!"XITONG".equals(tablename)){
	   		 request.setAttribute("headershow",",'"+java.net.URLDecoder.decode(request.getParameter("cnname"),"UTF-8")+"'");
	    }else{
	    	request.setAttribute("headershow",",'"+java.net.URLDecoder.decode(request.getParameter("cnname"),"UTF-8")+"','部位'");
	    }
	    request.setAttribute("disnameshow",disnameshow);
	    request.setAttribute("disnameshow1",disnameshow1);
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">   								
	<head> 							
		<title></title>	
		<%@ include file="../jslib/jquerylib.jsp" %>
		<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
		<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
		<link rel="stylesheet" type="text/css" media="screen" href="<%=request.getContextPath() %>/jslib/mypage.js" />
	       <!-- 删除结果信息返回 -->
	    	<c:if test="${requestScope.message!=null}">
				<script type="text/javascript">
	  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
	  	 		     window.close();
	  			</script>
	        </c:if>
	 
	<script type="text/javascript">
	var cnname = '<%=java.net.URLDecoder.decode(request.getParameter("cnname"),"UTF-8") %>';
	$(document).ready(function(){
		var value = '<%=request.getParameter("byTableValueId")%>';
		document.getElementById("byTableValue").value =value;
	   //如果是选择工艺 列表显示工艺原文
	    var colmodelStr = '';
	    var fileColname = '';
	    var colname1 = '';
	    if('${tablename}'=='DIC_STANDARD'){
	         colname1 = "工艺原文";
	         fileColname =","+'${fileColname}';
	    }
		$("#gridTable").jqGrid({					
			//url:'<%=request.getContextPath() %>/auto!queryChooseData.action?byTableValueId=<%=request.getParameter("byTableValueId")%>&flowid=${flowid}&orgid=${orgid}&disname=${disname}&unittype=${unittype}&formid=${formid}&fileName=${fileName}&media=${media}&temp='+Math.round(Math.random()*10000),
			url:'<%=request.getContextPath() %>/auto!queryChooseData.action?byTableValueId=<%=request.getParameter("byTableValueId")%>&cnname=<%=request.getParameter("cnname")%>&flowid=${flowid}&orgid=<%=request.getParameter("orgid")%>&disname=${disname}&unittype=${unittype}&formid=${formid}&fileName=${fileName}&media=${media}&temp='+Math.round(Math.random()*10000),
			
			datatype: "json",
			height: 300,
			autowidth: true, 
			colNames:[''${headershow},colname1],
			colModel:[
					{name:'${colname}',index:'${colname}',key:true,hidden:true,hidedlg:true}, 
					${disnameshow}		
					{name:'${fileColname}',index:'${fileColname}', width:160,formatter: function(cellvalue, options, rowObject) {
						  return "<a href='<%=request.getContextPath()%>/codereviewNew/downloadFile.action?flag=0&fileName="+escape(encodeURIComponent(rowObject.${fileColname}))+"'  target='_blank'>"+rowObject.${fileColname}+"</a>" }},
			         ]
			          ,
			shrinkToFit:false,
			sortname:'id',
			sortorder:'desc',
			viewrecords:true,
			multiselect: true, // 是否显示复选框
			multiboxonly : true, 
			//gridview: true,  //提升速度
			rownumbers: true,//显示行号
			rownumWidth: 30, //行号的宽度
			rowNum:<%=session.getAttribute("SYS_PAGECOUNT")%>,
			rowList:[15,20,50,200,500],
			toolbar: [false,"top"],
			jsonReader: {
				root:"rows",		// 数据行（默认为：rows）
				page: "page",  // 当前页
				total: "total",  // 总页数
				records: "records",  // 总记录数
				repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
			},
			ondblClickRow : function(rowid) {
				var id = '<%=request.getParameter("id")%>';
				var row = $("#gridTable").jqGrid("getRowData", rowid); 
				//var array = "{'ID':'"+row.ID+"','NAME':'"+row.${disname}+"'}";
				var array = "${disnameshow1}";
				//window.returnValue=array;
           		//window.opener.document.getElementById("data_"+id).value=row.${disname};
         		//window.opener.document.getElementById(id).value=row.ID;
         		window.opener.document.getElementById(id).value=row.${disname};
         		//填写单位
         		if(id=='SIGNEDUNIT')
         		{
         			//alert(row.ORG_ID);
         			window.opener.document.getElementById("orgid").value=row.ORG_ID;
         		}
         		//设计单位
         		/*if(id=='DESIGNUNIT')
         		{
         			window.opener.document.getElementById("DESIGNAPTITUDE").value=row.UNIT_APTITUDE;
         			window.opener.document.getElementById("DESIGNLEVEL").value=row.UNIT_LEVEL;
         			window.opener.document.getElementById("DESIGNSTANDARD").value=row.UNIT_STANDARD;
         		}
         		//施工单位
         		if(id=='BUILDER')
         		{         
         			window.opener.document.getElementById("BUILDERLEVEL").value=row.UNIT_LEVEL;
         			window.opener.document.getElementById("BUILDSTANDARD").value=row.UNIT_STANDARD;
         		}
         		//监理单位
         		if(id=='SUPERVISORUNIT')
         		{        
         			window.opener.document.getElementById("SUPERVISORLEVEL").value=row.UNIT_LEVEL;        		
         			window.opener.document.getElementById("DESIGNSTANDARD").value=row.UNIT_STANDARD;
         		}*/
				window.close();
			},
			prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
			pager:"#gridPager",
			postData : {
     			columns : "${colname},${disname}"+fileColname,
     			//columns : "${colname}"+fileColname,
     			tableName:"${tablename}"
     		},
			caption: "列表"	
								
	    });
	 if('${tablename}'!='DIC_STANDARD'){
		 $("#gridTable").jqGrid('hideCol',['${fileColname}']);
	 }					
	 jQuery("#gridTable").jqGrid('navGrid','#gridPager',{add:false,edit:false,del:false,search:false,refresh:false});
		jQuery("#gridTable").jqGrid('navButtonAdd','#gridPager',
					{ 	
					caption: "列状态",                          
					title: "Reorder Columns",                           
					onClickButton : function (){                               
					jQuery("#gridTable").jqGrid('setColumns');                           
					}
		}); 
		
		$('#entry').click(function() {
           		var rowid = $("#gridTable").getGridParam("selarrrow")+"";
           		//alert(rowid);
           		if(!rowid){
           		   alert("请选择数据!");
           		   return false;
           		}
				var id = '<%=request.getParameter("id")%>';
           		//window.opener.document.getElementById(id).value=rowid;
           		var strids=rowid.split(","); //字符分割
				var num=strids.length;
				var disnames="";
				for(i=0;i<num;i++)
				{
					var rowid=strids[i];					
					var row = $("#gridTable").jqGrid("getRowData", rowid); 					
					disnames+=row.${disname};
					disnames+=",";
				}
           		disnames=disnames.substring(0,disnames.length-1);
           		window.opener.document.getElementById(id).value=disnames;
				window.close();
				return false;
	  		});
		
		
		   /* $('#entry').click(function() {
           		var rowid = $("#gridTable").getGridParam("selarrrow")+"";
           		if(!rowid){
           		   alert("请选择数据!");
           		   return false;
           		}
				if(rowid.indexOf(",")!=-1){
					  alert("只能选择一条记录!");  
				      return false; 
				 }
				//var row = $("#gridTable").jqGrid("getRowData", rowid);  
				var returnValue ="{'ID':'"+rowid+"'";
				var colum = '${disname}';
				var allColum = colum.split(",");
				for(var i=0;i<allColum.length;i++){
				   var columName = allColum[i];
				   returnValue = returnValue+",'"+columName+"':'"+eval('row.'+columName)+"'";
				}
				returnValue = returnValue+"}"; 
				          		
           		//window.returnValue = returnValue;
           		//window.opener.document.getElementById("data_"+id).value=row.${disname};
         		//window.opener.document.getElementById(id).value=row.ID;	
				var id = '<%=request.getParameter("id")%>';
           		window.opener.document.getElementById(id).value=row.${disname};
				window.close();
				return false;
	  		});*/
	  		/**
		     * 取消
		     */
		    $("#center").click(function(){
		        window.close();
		    });
	}); 
	 
	//查询
	function gridSearch(){
	    var allqueryValue="";
	    if("${requestScope.queryColumns}"!=''){
	       var arr = "${requestScope.queryColumns}".split(",");
	       for(var i=0;i<arr.length;i++){
	          if($.trim($('#'+arr[i]).val())!=''){
	             allqueryValue= allqueryValue+"&"+arr[i]+"="+encodeURIComponent(encodeURIComponent($.trim($('#'+arr[i]).val())));
	          }
	          
	       }
	    }
		var params = {
				//${requestScope.queryValue}
				columns : "${colname},${disname}",
     			tableName:"${tablename}",
     			queryValue:encodeURIComponent($('#queryColumn').val()),
     			disname: '${disname}',
     			formid: '${formid}',
     			byTableValueId: '<%=request.getParameter("byTableValueId")%>',
     			queryColumn:"${requestScope.queryColumns}"
     			
		};
		 var postData = $("#gridTable").jqGrid("getGridParam", "postData");
		 $.extend(postData, params);
		jQuery("#gridTable").jqGrid('setGridParam',
		{
			url:'<%=request.getContextPath() %>/auto!queryChooseData.action?flowid=${flowid}&disname=${disname}&formid=${formid}&fileName=${fileName}'+allqueryValue+'&temp='+Math.round(Math.random()*10000)
		}).trigger("reloadGrid", [{page:1}]);
    } 
	</script>	
	</head>
	<body>

	<form action="" method="post" ">
		 <table width="100%" border="0" cellpadding="6" cellspacing="0" class="tabman" style="width:100%;margin-bottom:0px">
			<tr>
				<td>
				 <input type="hidden" id="byTableValue" name="byTableValue" value=""/>
				 <!--  
				 <%=java.net.URLDecoder.decode(request.getParameter("cnname"),"UTF-8") %>：<input type="text" id="queryColumn" />
				 -->
				${queryContent }
				
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="button_b" value="查询" onclick="gridSearch()"/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="button_b" value="清空" onclick="reset()"/>
				</td>
			</tr>
				</table>		
			<table style="width: 100%;" class="tableCont"> 
			<tr>
				<td colspan="4">
					<table id="gridTable"></table>
					<div id="gridPager"></div>
				</td>
			</tr>
			<tr>
            	<td colspan="4" style="text-align:center;height:20px;font-size:15px;font-weight:bold;">
					<button id="entry" class="button_b">确&nbsp;定</button>&nbsp;&nbsp;&nbsp;
        			<button id="center" class="button_b">取&nbsp;消</button>
				</td>
        	</tr>
		</table>
		</form>
	</body>
</html>
